package hibernate.method;

import hibernate.method.interfaces.TableEntityMethodsInterface;
import hibernate.model.TableEntity;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

public class TableEntityMethods implements TableEntityMethodsInterface{

	@Override
	public List<TableEntity> listAllTable(SessionFactory sessionFactory,
			Session session) {
			Criteria cr = session.createCriteria(TableEntity.class);
			@SuppressWarnings("unchecked")
			List<TableEntity> telist = cr.list();
			return telist;
		}

	@Override
	public void addTable(SessionFactory sessionFactory, Session session,
			int local_id, String value, String label, int persons,
			String smoking) {
		TableEntity te = new TableEntity();
		te.setLocal_id(local_id);
		te.setValue(value);
		te.setLabel(label);
		te.setPersons(persons);
		te.setSmoking(smoking);
		session.save(te);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TableEntity> listTablesByLocalId(SessionFactory sessionFactory,
			Session session, int local_id) {
		Criteria criteria = session.createCriteria(TableEntity.class);
		criteria.add(Restrictions.eq("local_id", local_id));
		return criteria.list();
	}

	@Override
	public TableEntity getTableById(SessionFactory sessionFactory,
			Session session, int table_id) {
		TableEntity table = (TableEntity) session.get(TableEntity.class, new Integer(table_id));
		return table;
	}
	
	
	

}
